﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wechat.Util.Paged;

namespace Wechat.Dao
{
    public interface IRepository<T> where T : class
    {
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        T Get(int id);

        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="table">根据字段</param>
        /// <param name="key">根据字段</param>
        /// <param name="value">字段值</param>
        /// <returns></returns>
        IList<T> GetByKey(string table, string key, object value);

        /// <summary>
        /// 获取全部实体
        /// </summary>
        /// <returns></returns>
        IList<T> GetAll();

        /// <summary>
        /// 插入实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Insert(T entity);

        /// <summary>
        /// 批量插入实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Insert(IEnumerable<T> list);

        /// <summary>
        /// 批量插入，事务处理
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        int InsertTran(IEnumerable<T> list);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Update(T entity);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Delete(T entity);

        /// <summary>
        /// 根据条件查询
        /// </summary>
        /// <param name="queryString">查询语句</param>
        /// <param name="param">参数对象</param>
        /// <returns></returns>
        IList<T> LoadByCondition(string queryString, object param);

        /// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="criteria">分页请求参数</param>
        /// <returns></returns>
        PagedList<TModel> GetPageDataList<TModel>(PageCriteria criteria) where TModel : class;

        /// <summary>
        /// 执行简单存储过程，返回受影响行数
        /// </summary>
        /// <param name="param"></param>
        /// <param name="procName"></param>
        /// <returns></returns>
        int ExecByProcedure(object param, string procName);

        /// <summary>
        /// 执行sql，返回受影响的行数
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数对象</param>
        /// <returns></returns>
        int ExecuteSql(string sql, object param = null);

        /// <summary>
        /// 执行sql，返回一行一列值
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="param">参数对象</param>
        /// <returns></returns>
        object ExecuteScalar(string sql, object param = null);
    }
}
